using System;

namespace ZeBobo5.LibraryHelper.Orm
{
    public sealed class OrmValues<T> : OrmValuesBase
    {
        internal OrmValues()
        {
        }

        public T CurrentValue
        {
            get
            {
                return (T)_currentValue;
            }
            set
            {
                OnFieldChanging();
                _currentValue = value;
                OnFieldChanged();
            }
        }

        public T OriginalValue
        {
            get
            {
                return (T)_originalValue;
            }
            internal set
            {
                _originalValue = value;
            }
        }

        internal void OnFieldChanging()
        {
            if (FieldChanging != null)
            {
                FieldChanging(this, EventArgs.Empty);
            }
        }

        internal void OnFieldChanged()
        {
            if (FieldChanged != null)
            {
                FieldChanged(this, EventArgs.Empty);
            }
        }

        internal event EventHandler FieldChanging;
        internal event EventHandler FieldChanged;

        public override string ToString()
        {
            return CurrentValue.ToString();
        }
    }
}